<template>
  	<div class="page-content">
		

     <el-tabs v-model="activeName">
       <el-tab-pane label="饮水记录" name="first">
          
      <!-- 条件筛选 -->
    	<table-bar :showTop="false"  @changeColumn="changeColumn">
      <div slot="top">
        <el-form label-width="70px" :model="params" ref="tiaojianRef" :rules="paramsRules">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="操作人：" prop="operator">
                  <el-input placeholder="操作人" v-model="params.operator"></el-input>
                </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="鸽棚：" prop="dovecoteNumber">
                <el-input placeholder="鸽棚" v-model="params.dovecoteNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
             <el-col :xs="24" :sm="12" :lg="6">
                 <el-form-item label="开始时间" label-width="95px" prop="startTime">
                       <el-date-picker                                          
                         v-model="params.startTime"                    
                         type="datetime"
                         value-format="yyyy-MM-dd HH:mm:ss" 
                         placeholder="选择日期时间">
                        </el-date-picker>
                 </el-form-item>
             </el-col>
             <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="截止时间" label-width="95px" prop="endTime">
                       <el-date-picker                     
                         v-model="params.endTime"
                         type="datetime"
                         value-format="yyyy-MM-dd HH:mm:ss" 
                         placeholder="选择日期时间">
                       </el-date-picker>
                   </el-form-item>
             </el-col>
            <el-row :xs="24" :sm="12" :lg="6" style="float: right; margin-right: 10px;">
              <el-button type="primary" @click="search">搜索</el-button>
              <el-button @click="reset">重置</el-button>
            </el-row>
          </el-row>
        </el-form>
      </div>
      <div slot="bottom">
        <el-button type="primary" plain  @click="adddrinkingdialog=true">添加用户</el-button> 
        <el-button type="danger" plain @click="multipledelete">批量删除</el-button>    
      </div>
    	</table-bar>
    
    	<!-- 操作人信息表格 -->
        <el-table ref="multipleTable" :data="userList" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
        	<el-table-column type="selection" width="55"></el-table-column>
      		<el-table-column type="index" ></el-table-column>
      		<el-table-column label="操作人" prop="operator"/>
      		<el-table-column label="鸽棚" prop="dovecoteNumber"/>
      		<el-table-column label="开始操作时间" prop="startTime"/>
      		<el-table-column label="结束操作时间" prop="endTime" />
      		<el-table-column label='操作'  width='300px'>
            <template  slot-scope="scope" width='300px'>
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="showdrinkingdialog(scope.row)">编辑</el-button>
                 <el-button size="mini" type="danger" icon="el-icon-delete" @click="removedoperator(scope.row.id)">删除</el-button>
            </template>
         </el-table-column>
    	
      
      </el-table>
      
     <!-- 分页区域 -->
	  	<el-pagination  @size-change="SizeChange" @current-change="CurrentChange" :current-page="queryinfo.pagenum"
                 :page-sizes="[5, 10, 15, 20]" :page-size="queryinfo.pagesize" layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
      </el-pagination>
       </el-tab-pane>

       <el-tab-pane label="饮水机器" name="second">

       <!-- 抽水泵条件筛选 -->
    	<table-bar :showTop="false"  @changeColumn="changeColumn">
      <div slot="top">
        <el-form label-width="70px" :model="mparams" ref="tiaojianRef" :rules="paramsRules">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="启动状态：" prop="open" label-width="100px">
                   <el-input placeholder="启动状态" v-model="mparams.open"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="鸽棚：" prop="dovecoteNumber">
                <el-input placeholder="鸽棚" v-model="mparams.dovecoteNumber"></el-input>
              </el-form-item>
            </el-col>
          
            <el-row :xs="24" :sm="12" :lg="6" style="float: right; margin-right: 10px;">
              <el-button type="primary" @click="msearch">搜索</el-button>
              <el-button @click="reset">重置</el-button>
            </el-row>
          </el-row>
        </el-form>
      </div>
      <div slot="bottom">
        <el-button type="primary" plain @click="madddrinkingdialog=true" >添加机器</el-button> 
        <el-button type="danger" plain @click="multimachinedelete">批量删除</el-button>  
      </div>
    	</table-bar>

          <!-- 抽水泵信息表格 -->
      <el-table size="mini" ref="multipleTable" :data="machineList" tooltip-effect="dark" style="width: 100%" @selection-change="handleMachineChange">
       	  <el-table-column type="selection" width="55"></el-table-column>
         	<el-table-column type="index" ></el-table-column>
         	<el-table-column label="机器编号" prop="machineNumber"/>
         	<el-table-column label="鸽棚" prop="dovecoteNumber"/>
          <el-table-column label="峰值扬程" prop="peakHead"/>
          <el-table-column label="峰值吸程" prop="peakSuction"/>
          <el-table-column label="峰值流量" prop="peakFlow"/>
          <el-table-column label="转速" prop="rev"/>   
         	<el-table-column label="开始操作时间" prop="startTime" width="150px"/>
         	<el-table-column label="结束操作时间" prop="stopTime" width="150px"/>
           <el-table-column label="状态">
            <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.open"
                  active-color="#409eff"
                  inactive-color="#dcdfe6"
                   @change="changemachine(scope.row)"
                  >
                </el-switch>
            </template>
          </el-table-column>
         	<el-table-column label='操作'  width='180px'>
           <template  slot-scope="scope">
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="meditdrinking(scope.row)">编辑</el-button>
                 <el-button size="mini" type="danger" icon="el-icon-delete" @click="removemachine(scope.row.id)">删除</el-button>
            </template>
         </el-table-column>
    	</el-table>
     <!-- 分页区域 -->
	  	<el-pagination  @size-change="mSizeChange" @current-change="mCurrentChange" :current-page="mqueryinfo.mpagenum"
                 :page-sizes="[5, 10, 15, 20]" :page-size="mqueryinfo.mpagesize" layout="total, sizes, prev, pager, next, jumper"
                  :total="mtotal">
      </el-pagination>

       </el-tab-pane>
     </el-tabs>
     
      <!-- 添加用户对话框 -->
      <el-dialog  title="添加操作人信息"  :visible.sync="adddrinkingdialog"  width="50%" @close="addDialogClosed">
          <el-form :model="addInfo"  ref="addRef" :rules="operatorRules" label-width="110px">
                 <el-form-item label="操作人:" prop="operator" >
                   <el-input v-model="addInfo.operator"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                   <el-select v-model="addInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>               
                 <el-form-item label="开始操作时间:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="addInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="结束操作时间:">
                    <el-date-picker
                      prop="endTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="addInfo.endTime"
                      type="datetime"
                      placeholder="选择日期时间">
                    </el-date-picker>
                 </el-form-item>              
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="adddrinkingdialog=false">取 消</el-button>
             <el-button type="primary" @click="adduser()">确 定</el-button>
            </span>
       </el-dialog>
       <!-- 编辑操作人对话框 -->
        <el-dialog  title="编辑操作人信息"  :visible.sync="drinkingdialog"  width="50%" @close="editDialogClosed">
          <el-form :model="userInfo"  ref="editRef" :rules="operatorRules" label-width="110px">
                 <el-form-item label="操作人:" prop="operator" >
                   <el-input v-model="userInfo.operator"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚编号:" prop="dovecoteNumber">
                   <el-select v-model="userInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>
                  <el-form-item label="开始操作时间:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="userInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="结束操作时间:">
                    <el-date-picker
                      prop="endTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="userInfo.endTime"
                      type="datetime"
                      placeholder="选择日期时间">
                    </el-date-picker>
                 </el-form-item>              
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="drinkingdialog=false">取 消</el-button>
             <el-button type="primary" @click="edituser(userInfo.id)">确 定</el-button>
            </span>
       </el-dialog>

        <!-- 添加机器对话框 -->
       <el-dialog  title="添加饮水机信息"  :visible.sync="madddrinkingdialog"  width="50%" @close="maddDialogClosed">
          <el-form :model="maddInfo"  ref="maddRef" :rules="machineRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber" >
                   <el-input v-model="maddInfo.machineNumber"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                   <el-select v-model="maddInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>
                  <el-form-item label="峰值扬程:" prop="peakHead">
                   <el-input v-model="maddInfo.peakHead" placeholder="单位：m"></el-input>
                 </el-form-item>
                  <el-form-item label="峰值吸程:" prop="peakSuction">
                   <el-input v-model="maddInfo.peakSuction" placeholder="单位：m"></el-input>
                 </el-form-item>
                  <el-form-item label="峰值流量:" prop="peakFlow">
                   <el-input v-model="maddInfo.peakFlow" placeholder="单位：m³/h"></el-input>
                 </el-form-item>
                 <el-form-item label="运行转速:" prop="rev">
                   <el-input v-model="maddInfo.rev" ></el-input>
                 </el-form-item>
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="madddrinkingdialog=false">取 消</el-button>
             <el-button type="primary" @click="addmachine">确 定</el-button>
            </span>
       </el-dialog>
        <!-- 编辑机器对话框 -->
        <el-dialog  title="编辑饮水机信息"  :visible.sync="meditdrinkingdialog"  width="50%" @close="editDialogClosed">
          <el-form :model="meditInfo"  ref="editRef" :rules="machineRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber" >
                   <el-input v-model="meditInfo.machineNumber"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                   <el-select v-model="meditInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>
                  <el-form-item label="峰值扬程:" prop="peakHead">
                   <el-input v-model="meditInfo.peakHead" placeholder="单位：m"></el-input>
                 </el-form-item>
                  <el-form-item label="峰值吸程:" prop="peakSuction">
                   <el-input v-model="meditInfo.peakSuction" placeholder="单位：m"></el-input>
                 </el-form-item>
                  <el-form-item label="峰值流量:" prop="peakFlow">
                   <el-input v-model="meditInfo.peakFlow" placeholder="单位：m³/h"></el-input>
                 </el-form-item>
                 <el-form-item label="运行转速:" prop="rev">
                   <el-input v-model="meditInfo.rev" ></el-input>
                 </el-form-item>
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="meditdrinkingdialog=false">取 消</el-button>
             <el-button type="primary" @click="editmachine (meditInfo.id)">确 定</el-button>
            </span>
       </el-dialog>

       <!-- 关闭机器对话框 -->
        <el-dialog  title="饮水机关机操作"  :visible.sync="closefeeddialog"  width="50%" @close="closemachinedialog">
          <el-form :model="closeInfo"  ref="closeRef" :rules="machineRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber">
                   <el-input v-model="closeInfo.machineNumber" disabled></el-input>
                 </el-form-item>              
                 <el-form-item label="操作人:" prop="operator">
                   <el-input v-model="closeInfo.operator" ></el-input>
                 </el-form-item>
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="mclosefeeddialog">取 消</el-button>
             <el-button type="primary" @click="mclosemachine">确 定</el-button>
            </span>
       </el-dialog>
  	</div>
</template>

<script>
import {
   getAllDovecoteNumber,
    userslist,
    edituser,
    deleteuser,
    adduser,
    multipledelete,
    machinelist,
    addmachine,
    editmachine,
    deletemachine,
    multimachinedelete,
    openmachine,
    closemachine
} from "../../../api/Dovecote/InfoManage/DrinkWater";

 
 
export default {
  	name: "DrinkWater",

  	meta: {
  	  	title: "饮水",
  	},

	data () {
      return {
        newdN:this.$store.state.Usersetting.CurrentDovecote.dovecoteNumber,
        activeName:'first',
        doptions:[],
        baseid:0,
        dvEdit: false,
        dialogTitle: '',
        form: {
          username: '',
          mibile: '',
          email: '',
          sex: 1,
          dep: '',
          status: true,
          userList1:[]
        },
        options: [{
          value: '1',
          label: 'A01'
        }, {
          value: '2',
          label: 'A02'
        }],
        value: '',
        userList: [],
        userInfo: {
          baseId: 0,
          operator: '',
          dovecoteNumber: '',
          startTime: '',
          endTime: ''
        },
      
        addInfo: {
          baseId: 0,
          operator: '',
          dovecoteNumber: '',
          startTime: '',
          endTime: '',
        },
        queryinfo :{
                // 自带参数，用于搜索
                 pagenum:1,
                 pagesize:10
            },
        total:0,
        drinkingdialog:false,
        adddrinkingdialog:false,
        idList:[],    
        operatorRules:{
           operator:[
                   { required: true, message: '请输入操作人名字', trigger: 'blur' },
                ],
           dovecoteNumber:[
                   { message: '请输入对应鸽棚', trigger: 'blur'},
                ],  
           startTime:[
                 { required: true, message: '请输入开始时间', trigger: 'blur'},
           ],
           endTime:[
                 { required: true, message: '请输入结束时间', trigger: 'blur'},
           ],  
        },
         // 搜索参数
        params:{
           dovecoteNumber:'',
           operator:'',
           startTime:'',
           endTime:'',
        },
         paramsRules:{
            operator:[
                   { message: '请输入操作人名字', trigger: 'blur' },
                ],
           dovecoteNumber:[
                   {  message: '请输入对应鸽棚', trigger: 'blur'},
                ],  
           startTime:[
                 { message: '请输入开始时间', trigger: 'blur'},
           ],
           endTime:[
                 {  message: '请输入结束时间', trigger: 'blur'},
           ],
     },
        machineList:[],
        mqueryinfo:{
          mpagenum:1,
          mpagesize:10
        },
        mtotal:0,
        mparams:{
          open:'',
          dovecoteNumber:''
        },
       madddrinkingdialog:false,
       maddInfo:{
          dovecoteNumber:'',
          machineNumber:'',
          peakFlow:'',
          peakHead:'',
          peakSuction:'',
          rev:'',
          baseId:0,
       },
       machineRules:{
           dovecoteNumber:[
                   { message: '请输入鸽棚编号', trigger: 'blur'}
           ],
            machineNumber:[
                   { message: '请输入机器编号', trigger: 'blur' ,required:true},
             ],
            peakFlow:[
                   { message: '请输入峰值流量', trigger: 'blur' ,required:true},
            ],
            peakSuction:[
                   { message: '请输入峰值吸程', trigger: 'blur' ,required:true},
            ],
            peakHead:[
                    { message: '请输入峰值扬程', trigger: 'blur' ,required:true},
            ],
            rev:[
                    { message: '请输入机器转速', trigger: 'blur' ,required:true},
            ],
            operator:[
                    { message: '请输入操作人', trigger: 'blur' ,required:true},
            ],
            
       },
       meditdrinkingdialog:false,
       meditInfo:{
            dovecoteNumber:'',
            machineNumber:'',
            peakFlow:'',
            peakHead:'',
            peakSuction:'',
            rev:'',
            baseId:0
       },
       midList:[],
       closeInfo:{
         operator:'',
         machineNumber:''
       },
       closefeeddialog:false
      };
    },
    created(){
        this.userslist();
        this.getdovecoteNumber();
        this.getmachinelist()
    },
    methods: {
      // 遍历对象，删除空属性值对应的属性
       filterParams(obj){
         let newPar = {};
       for (let key in obj) {
        //如果对象属性的值不为空，就保存该属性（做了限制，如果属性的值为0，保存该属性。如果属性的值全部是空格，属于为空。）
        if ((obj[key] === 0 || obj[key]) && obj[key].toString().replace(/(^\s*)|(\s*$)/g, '') !== '') {
            //记录属性
            newPar[key] = obj[key];
          }
       }
        //返回对象
        return newPar;
    },
     // 根据id选择对应的鸽棚
     async getdovecoteNumber(){
        this.baseid=this.$store.state.Usersetting.BaseInfo.id
        const{data:res}= await getAllDovecoteNumber(this.baseid);
        if(res.statusCode!==20000){
          return this.$message.error("获取鸽棚列表失败")
        }          
        this.doptions=res.data;
      },
      // 获取操作人信息
      async userslist(){
          this.params=this.filterParams(this.params);
         const {data:res}=await userslist(this.queryinfo.pagenum,this.queryinfo.pagesize,this.params);     
            if(res.statusCode!==20000){
             return this.$message.error('获取操作人信息失败')
         }else{
            this.userList=res.data.records;          
            this.total=res.data.total;           
         }
        // 要添加提前验证消息
      // 编辑接口
      },
      // 获取抽水泵信息
      async getmachinelist(){
        this.mparams=this.filterParams(this.mparams)
        const {data:res}=await machinelist(this.mqueryinfo.mpagenum,this.mqueryinfo.mpagesize,this.mparams)
        if(res.statusCode!==20000){
          return this.$message.error('获取抽水泵信息失败')
        }
        this.machineList=res.data.records;
        this.mtotal=res.data.total;            
     },
     mSizeChange(newsize){
         this.mqueryinfo.mpagesize=newsize;
         this.getmachinelist();
     },
     mCurrentChange(newnum){
        this.mqueryinfo.mpagenum=newnum;
        this.getmachinelist();
     },
       // 操作人搜索信息
      async search(){  
        this.params.dovecoteNumber=this.$store.state.Usersetting.CurrentDovecote.dovecoteNumber;
        this.params=this.filterParams(this.params);
       const {data:res}=await userslist(this.queryinfo.pagenum,this.queryinfo.pagesize,this.params);
            if(res.statusCode!==20000){
             return this.$message.error('所查询用户信息不存在！')
         }else{
            this.userList=res.data.records;
         };
      },
      // 抽水泵的信息查询
      async msearch(){
         this.mparams=this.filterParams(this.mparams);
         const{data:res}=await machinelist(this.mqueryinfo.mpagenum,this.mqueryinfo.mpagesize,this.mparams);
         if(res.data.records!==20000){
           return this.$message.error('所查询的抽水泵信息不存在！')
         }
         this.getmachinelist();
      },
      // 条件重置
      reset(){         
           this.$refs.tiaojianRef.resetFields();
      },

       // 编辑的把这一行的操作人信息赋值给userInfo
       showdrinkingdialog(item){           
            this.drinkingdialog=true
            this.userInfo = item
       },
      // 编辑操作人信息
       edituser(id){
        this.$refs.editRef.validate(async valid=>{
          if(!valid) return
             this.userInfo.baseId = +this.userInfo.baseId
        delete this.userInfo.id
          const {data:res}=await edituser(id,this.userInfo);      
          this.userslist();
          this.drinkingdialog=false;
        })
      },
      // 编辑,把这一行的操作人信息赋值给meditInfo
      meditdrinking(item){
          this.meditdrinkingdialog=true;
          this.meditInfo=item;   
       },
      // 编辑饮水机信息
      editmachine(id){
        this.$refs.editRef.validate(async valid=>{
             if(!valid) return;
             this.meditInfo.baseId = this.$store.state.Usersetting.BaseInfo.id;
             delete this.meditInfo.id;
             delete this.meditInfo.stopTime;
             delete this.meditInfo.startTime;
             delete this.meditInfo.open;
             const{data:res}=await editmachine(id,this.meditInfo);
             if(res.statusCode!==20000){
               return this.$message.error('编辑饮水机信息添加失败');
             }
             this.getmachinelist();
             this.meditdrinkingdialog=false;
        })
      },
        // 监听一页有多少条数据
        SizeChange(newsize){
           this.queryinfo.pagesize=newsize;
           this.userslist();
        },
        // 监听第几页
        CurrentChange(newcurrent){
           this.queryinfo.pagenum=newcurrent;
           this.userslist();
        },
      //  取消对话框内容重置
       editDialogClosed(){
          this.$refs.editRef.resetFields();
       },
      onSubmit() {
        this.dvEdit = false
      },
      // 删除用户信息
       async removedoperator(id){
           const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
            const {data:res}=await deleteuser(id);      
             if(res.statusCode!==20000){
                  return this.$message.error('获取操作人信息失败')
             }
  
             this.userslist()
      },
      // 机器根据id删除
      async removemachine(id){
           const confirmResult=await this.$confirm('此操作将永久删除该机器信息, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
             deletemachine(id).then(
              res => {             
                  this.getmachinelist();
              }
            ).catch(error=>{
               return this.$message.error('删除机器信息失败')
            })
      },
      // 添加用户
       async adduser(){
          this.$refs.addRef.validate( async valid=>{
               if(!valid) { return }
          const {data:res}=await adduser(this.addInfo);         
          this.userslist();
          this.addInfo.startTime='',
          this.addInfo.endTime='',
          this.$refs.addRef.resetFields();
          this.adddrinkingdialog=false;
         
       })
      },
      // 添加饮水机信息
      async addmachine(){
        this.$refs.maddRef.validate(async valid=>{
          if(!valid) return
          this.maddInfo.baseId +=this.maddInfo.baseId         
            const {data:res}=await addmachine(this.maddInfo);           
         if(res.statusCode!==20000){
           return this.$message.error('添加抽水泵机器信息失败')
         }
         this.madddrinkingdialog=false;
         this.getmachinelist();
        })
         
      },
      addDialogClosed(){
            this.$refs.addRef.resetFields();
        },
      maddDialogClosed(){
           this.$refs.maddRef.resetFields();
      },
      changeColumn(columns) {
        this.columns = columns
        this.$refs.table.doLayout()
      },
      // 监听批量删除
      handleSelectionChange(val){
           val.forEach(element => {
             this.idList.push(element.id);
           });
      },
      // 用户批量删除
      async multipledelete(){
           const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
            const {data:res}=await multipledelete(this.idList);
             if(res.statusCode!==20000){
                  return this.$message.error('获取操作人信息失败')
             }
             this.userslist()
            this.idList=[];
      },
      handleMachineChange(val){
            val.forEach(element=>{
              this.midList.push(element.id)
            })
      },
      async multimachinedelete(){
        const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
          const{data:res}=await multimachinedelete(this.midList);        
          if(res.statusCode!==20000){
            return this.$message.error('机器的批量删除失败')
          }
          this.getmachinelist();
          this.midList=[];
      },
      // 机器开关状态的判断
      async changemachine(item){
         if(item.open){
           const {data:res}=await openmachine(item.machineNumber);
           if(res.statusCode!==20000){
             return  this.$message.error('饮水机开启失败')
           }
         }
         else{
            this.closeInfo.machineNumber=item.machineNumber;
             this.closefeeddialog=true;
         }
      },
      closemachinedialog(){
         this.$refs.closeRef.resetFields();
       },
       mclosefeeddialog(){
         this.closefeeddialog=false;
        this.getmachinelist();
       },
      // 饮水机关闭
      async mclosemachine(){
        const {data:res}=await closemachine(this.closeInfo);
        // const{data:res}= await closemachine(this.closeInfo);
           this.closefeeddialog=false;
           this.$refs.closeRef.resetFields();          
      },
    }
  }
</script>
<style scoped>
.el-table td, .el-table th {
    text-align: center;
}
.el-tabs--top .el-tabs__item.is-top:nth-child(2) {
    padding-left: 16px
}
</style>
<style lang='scss' scoped>
  .page-content {
    width: 100%;
    height: 100%;

    .avatar {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
    .page {
        margin-top: 6px;
        text-align: center;
    }
  }
</style>